浏览量 4520
2015/01/30 01:36
package net.liezi.java.learn.initialization;
/**
* @author 王梓
*/
public class EnumOrder {
Spinciness degree;
public EnumOrder(Spinciness d ){
this.degree =d ;
}
public void describe(){
System. out.print("This burrito is:" );
switch (degree ) {
case NOT : System.out.println( "not spicy at all.");
break;
case MILD :
case MEDIUM :System.out.println("a little hot.");
break;
case HOT :
case FLAMING :
default: System.out.println("maybe too hot");
}
}
public static void main(String[] args){
Spinciness howHot=Spinciness. MEDIUM;
System. out.println(howHot +"\n" );
for(Spinciness s :Spinciness.values()){
System. out.println(s +".ordinal " +s .ordinal());
}
EnumOrder
plain= new EnumOrder(Spinciness.NOT),
greenChile=new EnumOrder(Spinciness.MEDIUM),
jalapeno= new EnumOrder(Spinciness.HOT);
plain.describe();
greenChile.describe();
jalapeno.describe();
}
}/*output
MEDIUM
NOT.ordinal 0
MILD.ordinal 1
MEDIUM.ordinal 2
HOT.ordinal 3
FLAMING.ordinal 4
This burrito is:not spicy at all.
This burrito is:a little hot.
This burrito is:maybe too hot
*/
上一篇 搜索 下一篇